<%@ page import="com.rihel.util.CartHelper" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="com.rihel.model.Goods" %>
<%@ page import="java.util.Set" %><%--
  Created by IntelliJ IDEA.
  User: rihel
  Date: 2018/3/15
  Time: 下午9:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="includes/head.jsp"/>

<%
    CartHelper cartHelper = null;
    HashMap<Goods,Integer> carts = null;
    if(session.getAttribute("cart")!=null){
        cartHelper=(CartHelper) session.getAttribute("cart");
        carts = cartHelper.getCarts();
    }

%>
<div class="container">
    <div class="row">
        <h2>购物车</h2>
    </div>
    <%if(carts==null || carts.size()==0){%>
       <div class="row">
           <div class="jumbotron col-12">
               <h2>当前购物车没有商品！</h2>
           </div>
       </div>
    <%}else{%>
    <div class="row">
        <table class="table table-hover">
            <thead>
            <tr>
                <th>商品名</th>
                <th>图片</th>
                <th>单价</th>
                <th>数量</th>
                <th>小计</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
                <%
                    Set<Goods> goodsSet = carts.keySet();
                    for (Goods goods: goodsSet) {
                        Integer count = carts.get(goods);
                        double xiaoji = count * goods.getPrice();
                %>
                    <tr>
                        <td><%=goods.getName()%></td>
                        <td><img style="width: 100px;" class="img-thumbnail" src="<%=goods.getPicUrl()%>"></td>
                        <td><%=goods.getPrice()%></td>
                        <td><%=count%></td>
                        <td><%=xiaoji%></td>
                    </tr>

                <%}%>
            </tbody>
        </table>
    </div>
    <%}%>
</div>
<jsp:include page="includes/foot.jsp"/>
